from safetensors.paddle import save_file
from paddlenlp.transformers import AutoModelForSequenceClassification, AutoTokenizer



model_name ='../model/ernie-sentiment-final'
# 加载PaddleNLP模型
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# 获取模型的参数
state_dict = model.state_dict()

# 定义保存路径
save_path = '../model/ernie-sentiment-final-convert'

save_file(state_dict, f'{save_path}/model.safetensors')

# 保存分词器
tokenizer.save_pretrained(save_path)
print(f"分词器已保存到 {save_path}")

# 保存模型配置
model.save_pretrained(save_path)
print(f"模型配置已保存到 {save_path}")
